{{- define "vsphere_cloud_config" }}
  {{- $providerClusterConfiguration := .Values.cloudProviderVsphere.internal.providerClusterConfiguration | required "internal.providerClusterConfiguration is required" }}
  {{- $vsphereDiscoveryData := .Values.cloudProviderVsphere.internal.vsphereDiscoveryData | required "internal.vsphereDiscoveryData is required" }}
global:
  user: {{ $providerClusterConfiguration.provider.username | quote }}
  password: {{ $providerClusterConfiguration.provider.password | quote }}
  insecureFlag: {{ $providerClusterConfiguration.provider.insecure }}

vcenter:
  main:
    server: {{ $providerClusterConfiguration.provider.server | quote }}
    datacenters:
      - {{ $vsphereDiscoveryData.datacenter | quote }}
nodes:
    {{- if not (empty $providerClusterConfiguration.externalNetworkNames) }}
  externalVmNetworkName: {{ join "," $providerClusterConfiguration.externalNetworkNames }}
    {{- end }}
    {{- if not (empty $providerClusterConfiguration.internalNetworkNames) }}
  internalVmNetworkName: {{ join "," $providerClusterConfiguration.internalNetworkNames }}
    {{- end }}

labels:
  region: {{ $providerClusterConfiguration.regionTagCategory | quote }}
  zone: {{ $providerClusterConfiguration.zoneTagCategory | quote }}

  {{- if $providerClusterConfiguration.nsxt }}

loadBalancer:
  ipPoolName: {{ $providerClusterConfiguration.nsxt.defaultIpPoolName | quote }}
  size: {{ $providerClusterConfiguration.nsxt.size | quote }}
  tier1GatewayPath: {{ $providerClusterConfiguration.nsxt.tier1GatewayPath | quote }}
    {{- if $providerClusterConfiguration.nsxt.defaultTcpAppProfileName }}
  tcpAppProfileName: {{ $providerClusterConfiguration.nsxt.defaultTcpAppProfileName | quote }}
    {{- end }}
    {{- if $providerClusterConfiguration.nsxt.defaultUdpAppProfileName }}
  udpAppProfileName: {{ $providerClusterConfiguration.nsxt.defaultUdpAppProfileName | quote }}
    {{- end }}
  snatDisabled: true

nsxt:
  user: {{ $providerClusterConfiguration.nsxt.user | quote }}
  password: {{ $providerClusterConfiguration.nsxt.password | quote }}
  host: {{ $providerClusterConfiguration.nsxt.host | quote }}
    {{- if $providerClusterConfiguration.nsxt.insecureFlag }}
  insecureFlag: {{ $providerClusterConfiguration.nsxt.insecureFlag }}
    {{- end }}
    {{- if $providerClusterConfiguration.nsxt.loadBalancerClass }}
loadBalancerClass:
      {{- range $lbc := $providerClusterConfiguration.nsxt.loadBalancerClass }}
        {{- printf "%s:" $lbc.name | nindent 2 }}
        {{- if $lbc.ipPoolName }}
    ipPoolName: {{ $lbc.ipPoolName | quote }}
        {{- end }}
        {{- if $lbc.tcpAppProfileName }}
    tcpAppProfileName: {{ $lbc.tcpAppProfileName | quote }}
        {{- end }}
        {{- if $lbc.udpAppProfileName }}
    udpAppProfileName: {{ $lbc.udpAppProfileName | quote }}
        {{- end }}
      {{- end }}
    {{- end }}
 {{- end }}
{{- end }}
---
apiVersion: v1
kind: Secret
metadata:
  name: cloud-controller-manager
  namespace: d8-cloud-provider-vsphere
  {{- include "helm_lib_module_labels" (list . (dict "app" "cloud-controller-manager")) | nindent 2 }}
type: Opaque
data:
  cloud-config: {{ include "vsphere_cloud_config" . | b64enc | quote }}
